using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using AjaxControlToolkit;
using System.Web.UI.MobileControls;
using System.Collections.Generic;
using Controladoras;
using EntidadesTO;
using System.Collections.Specialized;
using System.Web.Script.Services;


/// <summary>
/// Summary description for MotivoDeclaracion
/// </summary>

[System.Web.Script.Services.ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class MotivoDeclaracion : System.Web.Services.WebService
{

    public MotivoDeclaracion()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public CascadingDropDownNameValue[] ObtenerTipoMotivo(
        string knownCategoryValues,
        string category)
    {
        TipoMotivoMantenedor.ObtenerInstancia().CargarLista();
        List<TipoMotivoTO> listaTipoMotivo = TipoMotivoMantenedor.ObtenerInstancia().ListaTipoMotivo;

        List<CascadingDropDownNameValue> values =
          new List<CascadingDropDownNameValue>();
        foreach (TipoMotivoTO tipoMotivo in listaTipoMotivo)
        {
            string desTipoMotivo = tipoMotivo.DesTipoMotivo;
            int codTipoMotivo = tipoMotivo.CodTipoMotivo;
            values.Add(new CascadingDropDownNameValue(
              desTipoMotivo, codTipoMotivo.ToString()));
        }
        return values.ToArray();
    }

    [WebMethod]
    public CascadingDropDownNameValue[] ObtenerMotivoDeclaracion(
        string knownCategoryValues,
        string category,
        string contextKey)
    {
        StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(
          knownCategoryValues);
        int codTipoMotivo;
        if (!kv.ContainsKey("desTipoMotivo") ||
            !Int32.TryParse(kv["desTipoMotivo"], out codTipoMotivo))
        {
            return null;
        }


        MotivoDeclaracionMantenedor.ObtenerInstancia().CargarLista(codTipoMotivo);
        List<MotivoDeclaracionTO> listaMotivoDeclaracion = MotivoDeclaracionMantenedor.ObtenerInstancia().ListaMotivoDeclaracion;

        List<CascadingDropDownNameValue> values =
          new List<CascadingDropDownNameValue>();
        foreach (MotivoDeclaracionTO motivoDeclaracion in listaMotivoDeclaracion)
        {
            string desMotivoDeclaracion = motivoDeclaracion.DesMotivoDeclaracion;
            int codMotivoDeclaracion = motivoDeclaracion.CodMotivoDeclaracion;
            if (codMotivoDeclaracion.ToString() == contextKey)
                values.Add(new CascadingDropDownNameValue(
                            desMotivoDeclaracion, codMotivoDeclaracion.ToString(),true));
            else    
                values.Add(new CascadingDropDownNameValue(
                            desMotivoDeclaracion, codMotivoDeclaracion.ToString()));
        }
        return values.ToArray();
    }

}

